/*
 * Copyright (C) 2010 Imavis Srl
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.imavis.avimuxer;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;

/**
 * Raw muxer implementation.
 * <p>
 * This {@link Muxer} implementation writes all data directly to the output
 * file, unchanged, without any container format.
 *
 * @author Andrea Gualano
 */
final class RawMuxer implements Muxer {
    private final OutputStream out;
    private long length;

    RawMuxer(File file) throws IOException {
        this.out = new FileOutputStream(file);
        this.length = 0;
    }

    @Override
    public void write(byte[] data, Date timestamp) throws IOException {
        out.write(data);
        length += data.length;
    }

    @Override
    public void close() throws IOException {
        out.close();
    }

    @Override
    public long length() {
        return length;
    }
}
